using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ConsoleApplication1.Data;
using MongoDB;

namespace ConsoleApplication1.Util
{
    public class SetupData
    {
        string filename;
        Context context;
        public SetupData(string filename, Context c)
        {
            this.filename = filename;
            this.context = c;
        }
        public void Run()
        {
            Log.WriteLine("Running initial data setup.");
            Cleanup();
            CreateDefautMap();
        }
        void CreateDefautMap()
        {
            Log.WriteLine("Creating default map.");

            IMongoCollection<ParkingMap> coll = context.DB.GetCollection<ParkingMap>();

            ParkingMap map = new ParkingMap();
            map.Id = 1024;
            map.Places = HardCodedData.GetParkingPlaces();

            map.Camera = new Camera();

            map.Camera.LeftTop = new Point(169, 29);
            map.Camera.RightTop =        new Point(489, 62);
            map.Camera.LeftBottom =       new Point(-145, 350);
            map.Camera.RightBottom = new Point(356, 469);


            coll.Insert<ParkingMap>(new ParkingMap[] { map });

            Log.WriteLine("Created default map. Id: {0}, places cound: {1}.", map.Id, map.Places.Count);

        }
        void Cleanup()
        {
            Log.WriteLine("Removing all data.");

            IMongoCollection<ParkingMap> coll = context.DB.GetCollection<ParkingMap>();
            coll.Remove(new Document());
        }

        void ImportFile()
        {
            Log.WriteLine("Importing file {0}", filename);

            using (StreamReader r = new StreamReader(filename))
            {
                int lines = 0;
                string s;
                while ((s = r.ReadLine()) != null)
                {
                    lines++;


                }
            }
        }

    }
}
